/**
 * Created by Mark_ren on 2016/11/28.
 * 苟富贵,無相忘
 */
var moment = require("moment");
var co = require('co');
var seqModule = require('../../../routes/createModules');
var seq = new seqModule();
var util = require('../../../common/util');

var pfMemberController = {
    getPfMemberByMeetNum: function (req, res) {
        co(function () {
            var openId = req.query.openId;

            // var paramT = {};
            // var include = [{ model: seq.pfTotalScoreModule, as: 'pfTotalScores', attributes: [[seq.sequelize.fn('count', seq.sequelize.col('pfTotalScores.id')), 'isPf']], where: { judgeOpenId: openId }, required: false }];
            // paramT.include = include;
            // paramT.attributes = ["id", "headImg", "name", "tel", "hospitalName", "createTime"];
            // paramT.where = req.params;
            // seq.pfMemberModule.findAll(paramT).then(function (qdMeet) {
            //     res.json({ 'success': true, 'msg': '查询成功', 'result': qdMeet });
            // })  
            var sql = "select pfMem.id,pfMem.head_img as headImg,pfMem.name,pfMem.tel,pfMem.hospital_name as hospitalName,pfMem.create_time as createTime,(select count(*) from pf_total_score where player_id = pfMem.id and judge_open_id = '" + openId + "') as isPf from pf_member as pfMem where 1=1 ";
            sql += " and pfMem.meet_num = '" + req.params.meetNum + "' and pfMem.type = " + req.params.type;
            seq.sequelize.query(sql).spread(function (result) {
                res.json({ 'success': true, 'msg': '查询成功', 'result': result });
            })
        }).catch(function (e) {
            res.json({ 'success': false, 'msg': '查询失败' });
            console.log(e);
        })
    },
    addJudgeMember: function (req, res, next) {
        co(function () {
            req.query.id = util.getUUID().replace(/-/g, "");
            req.query.createTime = util.getNowTime();
            seq.pfMemberModule.create(req.query).then(function (qdMeet) {
                res.json({ 'success': true, 'msg': '添加成功', 'result': qdMeet });
            })
        }).catch(function (e) {
            res.json({ 'success': false, 'msg': '添加失败' });
            console.log(e);
        })
    }
}
module.exports = pfMemberController;